package simonxianyu.boot.mybatis;

import simonxianyu.boot.mybatis.base.BaseMapper;
import org.apache.ibatis.session.Configuration;
import org.mybatis.spring.mapper.MapperFactoryBean;

public class MyMapperFactoryBean extends MapperFactoryBean {

  private MapperHelper helper;

  public MyMapperFactoryBean() {
  }

  public MyMapperFactoryBean(Class mapperInterface) {
    super(mapperInterface);
  }

  @Override
  protected void checkDaoConfig() {
    Class<?> mapperClass = this.getMapperInterface();
    Configuration configuration = getSqlSession().getConfiguration();
    if (BaseMapper.class.isAssignableFrom(mapperClass)) {
      helper = new MapperHelper(mapperClass, configuration);
      helper.injectMapper(this);
    } else {
      super.checkDaoConfig();
    }
  }

  public void doCheckDaoConfig() {
    super.checkDaoConfig();
  }
}
